<!--
 * @Author: wjk
 * @Date: 2019-12-31 15:40:51
 * @LastEditors: xlm
 * @LastEditTime: 2021-08-11 13:25:51
 * @description: file content
 -->
<template>
  <base-page-view class-name="page-container">
    <view class="sLine_box one">
      <view class="sLine" @click="$navigateTo('/pagesMine/user-info/index')">
        <view class="lCont">
          个人资料
        </view>
        <view class="rCont">
          <image src="/static/images/mine/list_more.png" alt="" class="icon_my_more" />
        </view>
      </view>
      <view class="sLine" @click="$navigateTo('/pagesMine/address/address')">
        <view class="lCont">
          收货地址
        </view>
        <view class="rCont">
          <image src="/static/images/mine/list_more.png" alt="" class="icon_my_more" />
        </view>
      </view>
      <view class="sLine" @click="toRealName">
        <view class="lCont">
          实名认证
        </view>
        <view class="rCont">
          <span>{{ realStatus }}</span>
          <image src="/static/images/mine/list_more.png" alt="" class="icon_my_more" />
        </view>
      </view>
      <view class="sLine" v-if="userInfo.current_member_card_type === 3">
        <view class="lCont">
          董事价格隐藏设置
        </view>
        <view class="rCont">
          <switch @change="switchChange" :checked="isHiddenChairmanPrice" style="transform:scale(0.7)"/>
        </view>
      </view>
      <view class="sLine" @click="toDealPassword">
        <view class="lCont">
          交易密码
        </view>
        <view class="rCont">
          <span>{{ dealPasswordStatus }}</span>
          <image src="/static/images/mine/list_more.png" alt="" class="icon_my_more" />
        </view>
      </view>
    </view>
    <view class="sLine_box">
      <!-- <view class="sLine" @click="userlogout">
        <view class="lCont">
          注销账号
        </view>
        <view class="rCont">
          <image src="/static/images/mine/list_more.png" alt="" class="icon_my_more" />
        </view>
      </view> -->
      <view class="sLine" @click="goAbouteUs">
        <view class="lCont">
          关于我们
        </view>
        <view class="rCont">
          <image src="/static/images/mine/list_more.png" alt="" class="icon_my_more" />
        </view>
      </view>
    </view>
    <view class="login_out" @click="loginOut" @longpress="longpress">
      退出登录
    </view>
  </base-page-view>
</template>

<script>
import { mapActions } from 'vuex'
import './index.scss'
export default {
  components: {
  },
  data() {
    return {
      // 实名认证状态
      status: 2,
      realStatus: '',
      // 设置是否显示董事价
      isHiddenChairmanPrice: uni.getStorageSync('isHiddenChairmanPrice')||false,

      dealPasswordStatus: ''
    }
  },
  created() {
  },
  onLoad() {
  },
  onShow() {
    this.certificationGet()
    this.myInfo()
  },
  methods: {
    async certificationGet() {
      const real = await this.$api.commissionApi.certificationQuery()
      if (real.code === 0) {
        if (real.data) {
          this.status = real.data.status
          // 云账号认证状态
          this.status = real.data.status
          if (this.status === 3) {
            this.realStatus = '已实名'
          } else if (this.status === 2) {
            this.realStatus ='审核中'
          } else if (this.status === 4) {
            this.realStatus ='审核失败'
          } else {
            this.realStatus ='未实名'
          }
        }
      }
    },
    async myInfo(){
      const res = await this.$api.mineApi.getMy()
      if (res.code===0 && res.data && res.data.user) {
        let arr = ['未设置', '重置密码']
        this.dealPasswordStatus = arr[res.data.user.trade_password_flag||0]
      }
    },
    toRealName() {
      uni.removeStorageSync('realName')
      // this.$navigateTo(`/pagesMine/certification/index?examine=${this.status === 4}`)
      // return
      if (this.status === 3 || this.status === 2) {
        // 已实名3, 审核中(都无法点击修改)
        this.$navigateTo('/pagesMine/certification/index?updateRealname=true')
      } else {
        // 未实名或者审核中
        // 云账号认证状态
        // Submit("Submit", 2, "提交审核"),
        // NONE("NONE", 0, "NONE"),
        // Scuess("Scuess", 3, "成功"),
        // Fail("Fail", 4, "审核失败");
        this.$navigateTo(`/pagesMine/certification/index?examine=${this.status === 4}`)
      }
    },
    // 去设置交易密码
    toDealPassword(){
      let status = this.dealPasswordStatus === '重置密码' ? 1 : 0
      this.$navigateTo(`/pagesMine/dealPassword/index?status=${status}`)
    },
    userlogout() {
      // this.$gc.$message({
      //   content: '注销用户信息后将无法再使用该号码登录碧选，请慎重考虑是否注销?',
      //   title: '提示',
      //   confirmColor: '#fff',
      //   showMessage: true,
      //   confirmText: '确认注销',
      //   confirmBackground: '#FF759F',
      //   align: 'center',
      //   confirm: async() => {
      //     const res = await this.$api.mineApi.myInfoLogout()
      //     if (res.success) {
      //       this.LOGOUT_USER()
      //       uni.showToast({
      //         title: '注销成功',
      //         icon: 'none',
      //         duration: 2000,
      //         mask: true,
      //         success: () => {
      //           setTimeout(() => {
      //             uni.reLaunch({ url: '/pages/home/index' })
      //           }, 1000)
      //         }
      //       })
      //     }
      //   }
      // })
    },
    loginOut() {
      this.$gc.$message({
        content: '是否确定退出登录?',
        title: '提示',
        // confirmColor: '#fff',
        showMessage: true,
        confirmText: '确认',
        // confirmBackground: '#FF759F',
        align: 'center',
        confirm: () => {
          this.LOGOUT_USER()
          uni.reLaunch({ url: '/pages/home/index' })
          try {
            uni.removeStorageSync('publish_data')
          } catch (e) {
            // error
          }
        }
      })
    },
    async longpress() {
      const res = await this.$api.mineApi.getLogoutAllFlag()
      if (res.success && res.data) {
        this.$gc.$message({
          content: '强制退出您当前账号的所有设备？',
          title: '提示',
          confirmColor: '#fff',
          showMessage: true,
          confirmText: '确定',
          confirmBackground: '#FF759F',
          align: 'center',
          confirm: () => {
            this.loginOutAll()
          }
        })
      } else {
        this.loginOut()
      }
    },
    // 在所有设备退出当前用户
    async loginOutAll() {
      const res = await this.$api.mineApi.logoutAll()
      if (res.success) {
        this.LOGOUT_USER()
        uni.reLaunch({ url: '/pages/home/index' })
      }
    },
    goAbouteUs() {
      this.$navigateTo('/pagesMine/aboutus/index')
    },
    switchChange(e){
      console.log('zhi:', e.target.value)
      this.isHiddenChairmanPrice = e.target.value
      uni.setStorageSync('isHiddenChairmanPrice', this.isHiddenChairmanPrice)
    },
    ...mapActions(['LOGOUT_USER'])
  }
}
</script>
